package huoye.shops.huoye.mine.activity;

import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.codeideology.android.lang.entity.Paging;
import com.codeideology.android.widget.recycler.RecyclerViewAdapter;

import butterknife.BindView;
import butterknife.OnClick;
import huoye.shops.R;
import huoye.shops.base.PullToRefreshActivity;
import huoye.shops.huoye.mine.adapter.ManageAccountAdapter;
import huoye.shops.huoye.mine.model.AccountList;
import huoye.shops.huoye.mine.presenter.ManageAccountPresenter;
import huoye.shops.huoye.mine.view.IManageAccountView;
import huoye.shops.huoye.operation.activity.EditAddShopActivity;
import huoye.shops.huoye.user.model.User;
import huoye.shops.widget.CommonHintDialog;

public class ManageAccountActivity extends PullToRefreshActivity<AccountList> implements IManageAccountView {


    private ManageAccountAdapter adapter;
    private ManageAccountPresenter mManageAccountPresenter;

    @OnClick(R.id.manage_account_btn_add)
    void  onAddShopClick(){
        startActivity(AddAccoundCodeActivity.class);
    }


    @Override
    public RecyclerViewAdapter createAdapter() {
        adapter = new ManageAccountAdapter(this);
        adapter.setOnManageAccountDataListener(new ManageAccountAdapter.OnManageAccountListener() {
            @Override
            public void onDeleteClick(AccountList accountList) {
                showDeleteHint(accountList.getUserId());
            }

            @Override
            public void onEditClick(AccountList accountList) {
                accountList.setEidt(true);
                startActivity(EditAccoundActivity.class,accountList);
            }
        });
        return adapter;
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_manage_account;
    }

    @Override
    protected void initView(@Nullable Bundle bundle) {
        super.initView(bundle);
        setTitle("管理账户");
        mManageAccountPresenter = new ManageAccountPresenter();
        mManageAccountPresenter.addTaskListener(this);
        mManageAccountPresenter.onStart();
        query();
    }

    @Override
    public void onResume() {
        super.onResume();
        if(mManageAccountPresenter != null){
            query();
        }
    }

    @Override
    public void query(Paging paging) {
        super.query(paging);
        mManageAccountPresenter.getAccountList(paging);
    }

    @Override
    public void onItemClick(AccountList accountList, int i, View view) {

    }

    @Override
    public void refreshPage() {
        if(mManageAccountPresenter != null){
            query();
        }
    }


    private void showDeleteHint(String userId){
        CommonHintDialog commonHintDialog = new CommonHintDialog(this);
        commonHintDialog.setOnCommonHintListener(new CommonHintDialog.OnCommonHintListener() {
            @Override
            public void onLeftClick() {

            }

            @Override
            public void onRightClick() {
                mManageAccountPresenter.deleteAccount(userId);
            }
        });
        commonHintDialog.show();
        commonHintDialog.setDialogContent("确定要删除该账户？","取消","确定");

    }
}
